package cn.edu.cqytxy.string;

/**
 * StringBuffer演示
 *
 * @author yinjw
 */
public class StringBufferDemo {

    public static void main(String[] args) {
        // String s = "";
//        StringBuffer sb = new StringBuffer();
//        sb.append("四川省").append("成都市").append("青羊区").append("xxx");
//        String address = sb.toString();
//        System.out.println(address);

        long start = System.currentTimeMillis();
        stringBuilder();
        long end = System.currentTimeMillis();
        System.out.println("String拼接耗时：" + (end - start) + "ms");
    }

    /**
     * String字符串拼接
     */
    public static void stringTest() {
        String str = "";
        for (int i = 0; i < 100000; i++) {
            str += i;
        }
    }

    /**
     * StringBuilder字符串拼接
     */
    public static void stringBuilder() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 100000; i++) {
            sb.append(i);
        }
    }
}
